package com.shanzmoo.db.product.entity.dto;

import lombok.Data;

import java.util.*;

/**
 * spu 搜索结果
 * @author Gzhao 2020/12/29
 */
@Data
public class SpuSearchDto {

    /**
     * spuId
     */
    private String spuId;
    /**
     * 搜索权重
     */
    private Integer weight;

    public static List<SpuSearchDto> creatList(Map<String,Integer> map) {
        List<SpuSearchDto> result = new ArrayList<>();

        for (String spuId : map.keySet()){
            SpuSearchDto spuSearchDto = new SpuSearchDto();
            spuSearchDto.setSpuId(spuId);
            spuSearchDto.setWeight(map.get(spuId));

            result.add(spuSearchDto);
        }

        Collections.sort(result, Comparator.comparing(SpuSearchDto::getWeight).reversed());
        return result;
    }
}
